package com.avic.rong.goodsSort.adapter.drawerAdapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.avic.rong.R;
import com.avic.rong.goodsSort.bean.secondDrawerBean.GoodsSortGjDrawerOtherBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Chenjiaxin on 2019/7/15 20:22
 * E-Mail Address：16601203965@163.com
 * 价格面议
 */
public class GoodsSortGjDrawerPriceMianYiAdapter extends RecyclerView.Adapter<GoodsSortGjDrawerPriceMianYiAdapter.GoodsSortWdDrawerOtherViewHolder> {
    private Context context;
    private LayoutInflater inflater;
    private View view;
    //价格面议
    private List<GoodsSortGjDrawerOtherBean> priceMianYiList = new ArrayList<>();

    private GoodsSortGjDrawerPriceMianYiListener goodsSortGjDrawerPriceMianYiListener;

    public GoodsSortGjDrawerPriceMianYiListener getGoodsSortGjDrawerPriceMianYiListener() {
        return goodsSortGjDrawerPriceMianYiListener;
    }

    public void setGoodsSortGjDrawerPriceMianYiListener(GoodsSortGjDrawerPriceMianYiListener goodsSortGjDrawerPriceMianYiListener) {
        this.goodsSortGjDrawerPriceMianYiListener = goodsSortGjDrawerPriceMianYiListener;
    }

    public GoodsSortGjDrawerPriceMianYiAdapter(Context context) {
        this.context = context;
        inflater = LayoutInflater.from(context);
    }

    public void setPriceMianYiList(List<GoodsSortGjDrawerOtherBean> priceMianYiList) {
        this.priceMianYiList = priceMianYiList;
        notifyDataSetChanged();
    }

    @NonNull
    @Override
    public GoodsSortWdDrawerOtherViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        view = inflater.inflate(R.layout.view_goods_rv_item1, viewGroup, false);
        return new GoodsSortWdDrawerOtherViewHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull GoodsSortWdDrawerOtherViewHolder holder, int i) {
        holder.tv.setText(priceMianYiList.get(i).getAttrValue());
        holder.tv.setSelected(priceMianYiList.get(i).isSelected());
        holder.tv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goodsSortGjDrawerPriceMianYiListener.setPriceMianYiListSelected(i);
            }
        });
    }

    @Override
    public int getItemCount() {
        return priceMianYiList.size();
    }

    class GoodsSortWdDrawerOtherViewHolder extends RecyclerView.ViewHolder {
        TextView tv;

        public GoodsSortWdDrawerOtherViewHolder(@NonNull View itemView) {
            super(itemView);
            tv = itemView.findViewById(R.id.goods_Item_tv1);
        }
    }

    public interface GoodsSortGjDrawerPriceMianYiListener {
        void setPriceMianYiListSelected(int index);
    }
}
